<?php

setlocale(LC_ALL, "ru_RU.UTF-8");
mb_internal_encoding("UTF-8");

$curRealDir = mb_substr($_SERVER["SCRIPT_FILENAME"], 0, mb_strrpos($_SERVER["SCRIPT_FILENAME"], "/"));

require_once ("./config/setup.php");
require_once ("./libs/db.class.php");
require_once ("./libs/utils.inc.php");
$sm = new SSmarty();
$db = new DB();

//--из админки
$RSS_LAST_NEWS_COUNT = getOption($db, "RSS_LAST_NEWS_COUNT");
$RSS_MAX_LEN_PREVIEW = getOption($db, "RSS_MAX_LEN_PREVIEW");
//------------------

$db->dbq("
            Select
                newid as newid,
                caption as caption,
                maintext as maintext,
                DATE_FORMAT(postdate, \"%a, %d %b %Y %k:%i:%S GMT\") as postdate
            From
                news
            Order By
                position DESC
            Limit
                0,
                " . $RSS_LAST_NEWS_COUNT . "
        ");

$rss = array();
while ($arr = $db->assoc()) {
    $rssItem = array();

    $arr["maintext"] = bbCodeClear($arr["maintext"]);
    if (mb_strlen($arr["maintext"]) > $RSS_MAX_LEN_PREVIEW) {
        $arr["maintext"] = mb_substr($arr["maintext"], 0, $RSS_MAX_LEN_PREVIEW) . "...";
    }
    $arr = stripRecursive($arr);

    $rssItem["title"] = $arr["caption"];
    $rssItem["link"] = "http://" . DOMEN_NAME . "/news" . $arr["newid"] . ".html";
    $rssItem["description"] = $arr["maintext"];
    $rssItem["pubDate"] = $arr["postdate"];
    $rss[] = $rssItem;
}

$sm->assign("rss", $rss);
$sm->assign("displayedHtml", "rss.xml");
$sm->display("rss.xml");
?>
